package com.example.springboot0507.controller;

import com.example.springboot0507.basic.annotation.RequestJson;
import com.example.springboot0507.config.MpProperties;
import com.example.springboot0507.config.MpProperties2;
import com.example.springboot0507.config.OpProperties;
import com.example.springboot0507.entity.Dog;
import com.example.springboot0507.entity.Product;
import com.example.springboot0507.entity.User;
import com.example.springboot0507.service.FirstService;
import com.example.springboot0508.Person;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;
import java.util.Map;

/**
 * @author 王博
 */
@Slf4j
@RestController("firstController")
@RequestMapping("/first")
public class FirstController {

    @Resource
    private User user;

    @Resource
    private Dog dog;

    @Resource
    private MpProperties mpProperties;

    @Resource
    private MpProperties2 mpProperties2;

    @Resource
    private Person person;

    @Resource
    private OpProperties opProperties;

    @Resource
    private FirstService firstService;

    @GetMapping("/first")
    public String first(){
        System.out.println(mpProperties.getAppid());
        System.out.println(mpProperties.getSecret());
        System.out.println(mpProperties.getToken());
        System.out.println(mpProperties2.getAppid());
        System.out.println(mpProperties2.getSecret());
        System.out.println(mpProperties2.getToken());
        System.out.println(user);
        System.out.println(dog.getId());
        System.out.println(person);
        System.out.println(opProperties.getAppid());
        System.out.println(opProperties.getSecret());
        firstService.sayHello("王博");
        return "first";
    }

    @GetMapping("/getArray")
    public String getArray(Long[] arr) {
        log.info("getArray:{}", arr);
        return "getArray";
    }

    @GetMapping("/getList")
    public String getList(@RequestParam List<Long> list) {
        log.info("getList:{}", list);
        return "getList";
    }

    @GetMapping("/get")
    public String get(Long l) {
        log.info("get:{}", l);
        return "get";
    }

    @PostMapping("/postF")
    public String postF(@RequestParam List<Long> q) {
        log.info("postF:{}", q);
        return "postF";
    }

    @PostMapping("/postList")
    public String postList(@RequestBody List<Long> list) {
        log.info("postList:{}", list);
        return "postList";
    }


    @PostMapping("/postArray")
    public String postArray(@RequestBody Long[] arr) {
        log.info("postArray:{}", arr);
        return "postArray";
    }

    @PostMapping("/post")
    public String post(@RequestBody Long l) {
        log.info("post:{}", l);
        return "post";
    }

    @PostMapping("/postObj")
    public String postObj(@RequestBody Product p) {
        log.info("postObj:{}", p);
        return "postObj";
    }

    @PostMapping("/postObj2")
    public String postObj2(@RequestJson Integer id, @RequestJson String name) {
        log.info("postObj2:{}:{}", id,name);
        return "postObj2";
    }

    @PostMapping("/postObj3")
    public String postObj2(@RequestBody Map<String ,Object> params) {
        log.info("postObj3:{}", params);
        return "postObj3";
    }

    @GetMapping("/format")
    public String format(@NumberFormat(pattern = "#,###") Integer id) {
        log.info("format:{}", id);
        return "format";
    }


    @GetMapping("/getMuch")
    public String getMuch(Product product) {
        log.info("getMuch:{}", product);
        return "getMuch";
    }

    @PostMapping("/postParam")
    public String postParam(Product product) {
        log.info("postParam:{}", product);
        return "postParam";
    }

    @GetMapping("/getPath/{id}")
    public String postParam(@PathVariable @NumberFormat(pattern = "#,###") Integer id) {
        log.info("getPath:{}", id);
        return "getPath";
    }
}
